export default {
    data () {
        return {
            checkTypes: [{
                value: 0,
                label: '智能节假日'
            },
            {
                value: 1,
                label: '固定班次'
            },
            {
                value: 2,
                label: '排班制'
            },
            {
                value: 3,
                label: '按人员排班'
            },
            ],
            recordTypes: [{
                value: 10,
                label: '进行中'
            },
            {
                value: 20,
                label: '已完成'
            },
            {
                value: 30,
                label: '已撤回'
            },
            {
                value: 40,
                label: '强行中止'
            },
            {
                value: 45,
                label: '已拒绝'
            },
            {
                value: 50,
                label: '挂起'
            },
            {
                value: 99,
                label: '已废弃'
            }
            ],
            deviceType: [
                {value: 'MONITOR', label: '监控设备'},
                {value: 'BIKE', label: '巡查车'},
                {value: 'DDL', label: '电导率'},
                {value: 'YWY', label: '液位仪'},
                {value: 'LJMY', label: '垃圾满溢传感器'},
            ]
        }
    },
    computed: {
        navList () {
            const list = this.$store.state.siderBarList;
            return list.filter(item => !item.hidden && item.path != '/login')
        },
    },
    methods: {
        formatCheckType (v) {
            const item = this.checkTypes.find(c => c.value == v);
            return item.label;
        },
        formatRecordType (v) {
            if (v == '' || v == null) return '--'
            const item = this.recordTypes.find(c => c.value == v);
            return item.label;
        },
        getImgUrl (url) {
            if (!url) return [];
            return url.split(',').map(item => {
                return item.includes('http') ? item : window.$setting.baseImgUrl + item
            })
        },
        goPath (layoutCode, path, query) {
            const item = this.navList.find(item => item.code == layoutCode);
            this.$store.dispatch('setCurrentRoute', item)
            window.localStorage.setItem('navPath', item.path || item.children[0].path);
            this.$router.push({ path, query })
        },
        getTaskState (state) {
            const STATE_S = { 10: '进行中', 20: '已完成', 30: '已撤回', 40: '强行中止', 50: '挂起', 99: '已废弃' }
            return state ? STATE_S[state] : '--'
        },
        formatSoureType (type) {
            const opt = [
                {
                    label: '微信上报',
                    value: 'WECHAT'
                },
                {
                    label: 'AI上报',
                    value: 'AI'
                },
                {
                    label: '数字城管',
                    value: 'SZCG'
                },
                {
                    label: '设备上报',
                    value: 'DEVICE'
                },
                {
                    label: '文明创建办',
                    value: 'WMCJB'
                },
            ]
            if(!type) return '--';
            const item = opt.find(item => item.value == type);
            return item && item.label || '--'
        },
        isString(value) {
            return typeof value === 'string' || Object.prototype.toString.call(value) === '[object String]';
        },
        getConvertLocation(type, path, GW='84') {
            // type:1 点 2 二维面 3 三维面
            // path 坐标字符串`[120,30]`
            // GW 要得到的坐标类型 02 或者84
            if(!path) return null;
            let pathArr = this.isString(path) ? JSON.parse(path) : path;
            if(type == 1) {
                return GW == '84' ? this.GPS.GCJ02toWGS84(...pathArr):this.GPS.WGS84toGCJ02(...pathArr)
            }else if(type == 2){
                return pathArr.map(item => {
                    return GW == '84' ? this.GPS.GCJ02toWGS84(...item):this.GPS.WGS84toGCJ02(...item)
                })
            } else if (type == 3) {
                return pathArr.map(p => {
                    return p.map(item => GW == '84' ? this.GPS.GCJ02toWGS84(...item):this.GPS.WGS84toGCJ02(...item))
                })
            }
        }
    }
}
